/****************************************************************

this file is part of Music Practice Audio Player
Copyright (C)2012 Serhii Ratsyborynskyi (ratz@live.ru)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

******************************************************************/

#include "AudioTypeDef.hpp"


using namespace AudioProcessing;
Pan::Pan():mPan(0)
{

}

AudioProcessing::Pan::Pan(AudioProcessing::Panning p):mPan(p)
{
    checkLimits( mPan );
}

AudioProcessing::Panning AudioProcessing::Pan::setPan(AudioProcessing::Panning p)
{
    mPan = p;
    checkLimits( mPan );
    return mPan;
}

AudioProcessing::Panning AudioProcessing::Pan::getPan()
{
    return mPan;
}

void AudioProcessing::Pan::checkLimits(AudioProcessing::Panning &p)
{
    if( p > PAN_INTERVAL )
    {
        p = 100;
    }
    else if ( p < -PAN_INTERVAL )
    {
        p = - 100;
    }
}

AudioProcessing::dB::dB():mLevel(0)
{
    miLevel.multiplier = 0;
    miLevel.divider = 0;
}

AudioProcessing::dBf AudioProcessing::dB::setVolume(AudioProcessing::dBf level)
{
    mLevel = level;
    checkLimits( mLevel );
    calculateIVolume( mLevel , miLevel);
    return mLevel;
}

AudioProcessing::dBf AudioProcessing::dB::getVolume()
{
    return mLevel;
}

AudioProcessing::Volume AudioProcessing::dB::setIVolume(AudioProcessing::Volume level)
{
    miLevel = level;
    return miLevel;
}

AudioProcessing::Volume AudioProcessing::dB::getIVolume()
{
    return miLevel;
}

void AudioProcessing::dB::checkLimits(AudioProcessing::dBf &level)
{
    if( level > MAX_LEVEL )
    {
        level = MAX_LEVEL;
    }
    else if( level < -90.0 )
    {
        level = - 90.0;
    }

}

void AudioProcessing::dB::calculateIVolume(const AudioProcessing::dBf &level, AudioProcessing::Volume &iLevel)
{
    if( level > 0.0 )
    {
        iLevel.divider = 1;
        iLevel.multiplier = 0;
    }
    else
    {
        iLevel.divider = 1;
        iLevel.multiplier = 0;
    }
}
